/**
 * 
 */
package note;

import java.awt.Dimension;
import java.awt.LayoutManager;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JPopupMenu;
import javax.swing.JMenuItem;
import javax.swing.AbstractListModel;

/**
 * @author haiyuzha
 *
 */
public class NotebookListPanel extends JPanel {

	/**
	 * 
	 */
	public NotebookListPanel() {
		setLayout(new GridLayout(0, 1));
		DefaultListModel notebookListModel = new DefaultListModel();
		notebookListModel.addElement("Blackberry");
		notebookListModel.addElement("Linux");
		notebookListModel.addElement("Java");

		//JList notebookList = new JList(notebookListModel);
		ListMenu notebookList = new ListMenu(notebookListModel);
		JPopupMenu popupMenu = new JPopupMenu();
		JMenuItem menuItem0 = new JMenuItem("New notebook");
		JMenuItem menuItem1 = new JMenuItem("Delete");
		JMenuItem menuItem2 = new JMenuItem("Sort");
		popupMenu.add(menuItem0);
		popupMenu.add(menuItem1);
		popupMenu.add(menuItem2);
		
		JScrollPane notebookListScrollPane = new JScrollPane(notebookList);
		notebookListScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		notebookListScrollPane.setPreferredSize(new Dimension(120, 60));
		notebookListScrollPane.setBorder(BorderFactory.createCompoundBorder(
				BorderFactory.createTitledBorder("Notebooks"), 
				BorderFactory.createEmptyBorder(5, 5, 5, 5)));
		
		//add(popupMenu);
		add(notebookListScrollPane);
	}

	/**
	 * @param layout
	 */
	public NotebookListPanel(LayoutManager layout) {
		super(layout);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param isDoubleBuffered
	 */
	public NotebookListPanel(boolean isDoubleBuffered) {
		super(isDoubleBuffered);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param layout
	 * @param isDoubleBuffered
	 */
	public NotebookListPanel(LayoutManager layout, boolean isDoubleBuffered) {
		super(layout, isDoubleBuffered);
		// TODO Auto-generated constructor stub
	}

};
/*
class ListMenu extends JList implements MouseListener {
	private JPopupMenu popupMenu = null;
	private JMenuItem newItem = null;
	private JMenuItem deleteItem = null;
	private JMenuItem sortItem = null;

	public ListMenu(AbstractListModel model) {
		super(model);
		
		addMouseListener(this);
		
		popupMenu = new JPopupMenu();
		popupMenu.add(newItem = new JMenuItem("New"));
		popupMenu.add(deleteItem = new JMenuItem("Delete"));
		popupMenu.add(sortItem = new JMenuItem("Sort"));
		
		add(popupMenu);
	}
	
	public void action(ActionEvent e) {
		String str = e.getActionCommand();
		if (str.equals(newItem.getText())) {
			;
		} else if (str.equals(deleteItem.getText())) {
			;
		}
	}
	
	public JPopupMenu getPop() {
		return popupMenu;
	}
	
	public void setPop(JPopupMenu pop) {
		popupMenu = pop;
	}

	public void mouseClicked(MouseEvent e) {
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {
	}
	
	public void mousePressed(MouseEvent e) {
		if (e.getButton() == MouseEvent.BUTTON3) {
			newItem.setEnabled(true);
			deleteItem.setEnabled(true);
			sortItem.setEnabled(true);
			popupMenu.show(this, e.getX(), e.getY());
		}
	}
}
*/